package com.litree.service.services.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.litree.service.mapper.ICollectionMapper;
import com.litree.service.mapper.ILoginMapper;
import com.litree.service.model.CollectionBean;
import com.litree.service.services.ICollectionSerivce;

@SuppressWarnings({ "unchecked", "rawtypes" })
@Service
public class CollectionService implements ICollectionSerivce {

	@Autowired
	ICollectionMapper mapper;
	@Autowired
	ILoginMapper loginMapper;
	@Override
	public List getCollectionInfo(String loginName, int pageSize, int pageNo) {
		Map param =new HashMap();
		param.put("loginName",loginName);
		param.put("pageSize",pageSize);
		param.put("pageFrom", (pageNo-1)*pageSize);
		return mapper.getCollectionInfo(param);
	}

	@Override
	public Long getCollectionInfoCount(String loginName) {
		return mapper.getCollectionInfoCount(loginName);
	}


	@Override
	@Transactional
	public Integer setCollectionInfo(CollectionBean collectionBean) {
		Map param = new HashMap();
		param.put("loginName",collectionBean.getLoginName());
		param.put("pw",null);
		List list =loginMapper.getLoginInfo(param);
		if(list.size()>0){
			Map reslutMap = (Map) list.get(0);
			collectionBean.setLid((String)reslutMap.get("lid"));
			return mapper.setCollectionInfo(collectionBean);			
		}else{
			return 0;
		}
	}

	@Override
	public boolean checkCollectionStationInfo(String loginName, long stationId) {
		//true 已收藏  false 未收藏
		Map param=new HashMap();
		param.put("loginName", loginName);
		param.put("pw",null);
		param.put("stationId", stationId);
		List list =loginMapper.getLoginInfo(param);
		Map reslutMap = (Map) list.get(0);
		param.put("lid", reslutMap.get("lid"));
		List stationlist =mapper.checkCollectionStationInfo(param);
		if(stationlist.size()>0){
			return true;
		}else{
			return false;
		}
	}
	 
	
}
